﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace TY.UC.Common
{
    /// <summary>
    /// md5加密
    /// </summary>
    public class  Md5Helper
    {
        /// <summary>
        /// 16位加密
        /// </summary>
        /// <param name="convertString"></param>
        /// <returns></returns>
        public static string Get16Md5Str(string convertString)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(convertString)), 4, 8);
            t2 = t2.Replace("-", "");
            return t2;
        }

        /// <summary>
        /// 32位加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Get32Md5Str(string str)
        {
            byte[] result = Encoding.UTF8.GetBytes(str);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            return BitConverter.ToString(output).Replace("-", "").ToLower();
        }
    }
}
